home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16109 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Allowing interrupts in interrupt code
  5. Date: 9 Apr 1996 09:03:01 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ke1nlINNjcd@keats.ugrad.cs.ubc.ca>
  8. References: <3159B9DE.6140@igrin.co.nz>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <3159B9DE.6140@igrin.co.nz>,
  12. Steve Lowe  <lowefam@igrin.co.nz> wrote:
  13. >I have a routine attached to the timer interrupt.
  14.  
  15. Timer interrupts are not defined by the C language. You cannot write interrupt
  16. service routines in ANSI C. Your question is likely platform-specific.
  17.  
  18. >However, sometimes it takes more than one clock tick to execute - which 
  19. >causes endless headaches.
  20. >
  21. >Is there anything I can put in this routine so that an new interrupts 
  22. >can carry on?
  23.  
  24. Yes, you can put in a semaphore flag to indicate that you are currently doing
  25. busywork inside the interrupt handler. Then you reenable interrupts. When an
  26. interrupt arrives, it sees that the flag is set and will not enter the same
  27. region of code, but will instead do only basic housekeeping things like
  28. updating counters, calling other handlers in the interrupt chain and whatnot.
  29. It will not fiddle with the data that the first invocation is working on.
  30.  
  31. The real solution is to do time-slicing so that your lengthy task can be done
  32. as a thread dispatched by a scheduler. In a typical (single-CPU) OS
  33. implementation, tasks that can be done quickly are done with interrupts
  34. disabled. Tasks that take longer are done inside a critical region protected by
  35. semaphores rather than by interrupt masking, so that other processes can
  36. execute, and interrupts can be handled.
  37. -- 
  38.  
  39.